/**
 * Created by 丸子 on 2018/7/1.
 */
import Vue from 'vue'
import axios from 'axios'
import '../components'
// import store from '../store'
// import sessionStore from '../store/session'
import '../style/page.scss'
import Vant from 'vant'
import 'vant/lib/index.css'

import * as context from './context'
import { injectVueContext } from './index'
import '../filter'

Vue.use(Vant)

// process.env.NODE_ENV === 'production' ? require('../style/iconfont.scss') : require('../style/iconfont.dev.scss')

window.Vue = Vue

Vue.prototype.$bus = new Vue()

Vue.config.productionTip = false
// 判断生产环境
window.IS_PROD = process.env.NODE_ENV === 'production'

// 后端服务器 URL
window.API_HOST = process.env.NODE_ENV === 'production' ? '' : 'http://localhost:4003'

// WEB 根路径 URL
window.WEB_URL = process.env.NODE_ENV === 'production' ? '' : ''

// 后端服务器 API URL
window.API_BASE_URL = window.API_HOST + '/api'

Vue.prototype.$axios = axios
if (process.env.NODE_ENV !== 'production') {
  axios.defaults.withCredentials = true
}
axios.interceptors.request.use(function (config) {
  if (config.url.indexOf('?') === -1) {
    config.url += '?_c=' + Math.random()
  } else {
    config.url += '&_c=' + Math.random()
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.baseURL = window.API_BASE_URL

injectVueContext(context)

// v-lazy 1px
// Vue.use(VueLazyload, {
//   lazyComponent: true,
//   preLoad: 1.3,
//   error: 'dist/error.png',
//   // 一像素生成地址 http://png-pixel.com/
//   loading: '',
//   attempt: 1
// })

// store.registerModule('session', sessionStore())
